﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using Crawler.BusinessActions;
using Crawler.Model;

namespace WinFromsClient
{
    public partial class TestContentPageForm : Form
    {
        public TestContentPageForm(CaptureRuleInfo rule)
        {
            InitializeComponent();



            string achorPattern = @"(?<=<a [^>]+?>)[\s\S]*?(?=</a>)";
            string achorHref = @"(?<=href=[""']?)[\s\S]*?(?=[""']?[ |^>])";


            string html = Utilities.GetPageHTML(rule.TaskItem.Url);
            MatchCollection matches = Utilities.GetMatches(rule.StartString, rule.EndString, html);

            int cnt = 0;
            foreach (Match match in matches)
            {
                ListViewItem line = new ListViewItem();

                line.SubItems.Clear();
                line.SubItems[0].Text = (cnt++).ToString();
                line.SubItems.Add(Utilities.GetFirstMatch(achorPattern, match.Value));
                line.SubItems.Add(Utilities.GetFirstMatch(achorHref, match.Value));

                lv.Items.Add(line);
            }
        }
    }
}
